<?php
/**
 * dbfront
 * (c) 2010-2013 Stephen Adkins <spadkins@gmail.com>
 * This software began development in 2010.
 * It is based on code dating from 1999.
 *
 * License: GPL 2.0
 * The contents of this file may be used under the terms of
 * the GNU General Public License Version 2 or later (the "GPL").
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 * */
namespace App;
class Widget extends SessionObject {
    protected $content;
    public function html() {
        global $trace;
        if ($trace) trace_entry();
        if ($trace) trace_exit($this->name);
        return $this->html_escape($this->name);
    }
    public function html_escape($text) {
        global $trace;
        if ($trace) trace_entry();
        if (! isset($text)) {
            $text = '';
        }
        elseif ($text) {
            preg_replace(Array('&','<','>','"',"'"), Array('&amp;', '&lt;', '&gt;', '&quot;', '&#039;'), $text);
            # preg_replace('&', '&amp;',  $text);
            # preg_replace('<', '&lt;',   $text);
            # preg_replace('>', '&gt;',   $text);
            # preg_replace('"', '&quot;', $text);
            # preg_replace("'", '&#039;', $text);
        }
        if ($trace) trace_exit($text);
        return $text;
    }
#    public function content() {
#        try {
#            $html = $this->html();
#        }
#        catch (Exception $e) {
#            my ($name, $msg);
#            $msg = $e->getMessage();
#            preg_replace(Array('&','<','>','"',"\n"), Array('&amp;', '&lt;', '&gt;', '&quot;', "<br>\n"), $msg);
#            $html = <<EOF
#<table border="1" cellspacing="0">
#<tr><td bgcolor="#aaaaaa">
#<b>Widget Display Error: $this->name</b><br>
#</td></tr>
#<tr><td bgcolor="#ffaaaa">
#<font size="-1" face="sans-serif">
#$msg
#</font>
#</td></tr>
#</table>
#EOF
#        }
#
#        if (isset($this->content)) {
#            $content = $this->content;
#            $this->content = '';
#            return($content);
#        }
#
#        $title = "Widget";
#        $bodyoptions = "";
#            $title = $this->get("title");
#            $title = $this->get("name") if (!$title);
#            foreach $var ('bgcolor', 'text', 'link', 'vlink', 'alink',
#                          'leftmargin', 'topmargin', 'rightmargin', 'bottommargin') {
#                $value = $this->get($var);
#                if (defined $value && $value ne "") {
#                    $bodyoptions .= " $var=\"$value\"";
#                }
#                elsif ($var eq "bgcolor") {
#                    $bodyoptions .= " $var=\"#ffffff\"";
#                }
#            }
#        $bodyoptions .= " onLoad=\"$this->{onload_handler}\"" if ($this->{onload_handler});
#
#        my $context = $this->{context};
#        my $options = $context->{options};
#        my $response = $context->response();
#        my $context_head = $options->{"app.html.head"} || "";
#        my $context_body = "";
#        if ($response->{include}{css_list}) {
#            my $items = $response->{include}{css_list};
#            foreach my $item (@$items) {
#                if ($item =~ /^</) {
#                    $context_head .= $item;
#                }
#                else {
#                    $context_head .= "<link href=\"$item\" type=\"text/css\" rel=\"stylesheet\">\n";
#                }
#            }
#        }
#        if ($response->{include}{javascript}) {
#            my $items = $response->{include}{javascript_list};
#            foreach my $item (@$items) {
#                if ($item =~ /^</) {
#                    $context_head .= $item;
#                }
#                else {
#                    $context_head .= "<script src=\"$item\" type=\"text/javascript\" language=\"JavaScript\"></script>\n";
#                }
#            }
#        }
#
#        #$context_head = $this->{context}->head_html();
#        #$context_body = $this->{context}->body_html(\%main::conf);
#
#        my $session_html = $context->session()->html();
#        my $event_placeholder = '<input type="hidden" id="app-event-aux" name="app.event" value="">';
#        my $onload_support    = '<input type="hidden" id="app-loaded" name="app.loaded" value="">';
#
#        $context->get_messages();  # apparently, this also clears messages
#        delete $this->{messages};
#
#        my ($request);
#        my $form_options = "";
#        if ($context->can("request")) {
#            my $request = $context->request();
#            my $url = $request->url();
#            $form_options .= " action=\"$url\"";
#        }
#
#        my $content = <<EOF;
#    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
#    <html>
#    <head>
#    <title>${title}</title>
#    $context_head</head>
#    <body${bodyoptions}>
#    <form method="POST" id="mainform"${form_options}>
#    $session_html
#    $event_placeholder
#    $onload_support
#    $context_body
#    $html
#    </form>
#    </body>
#    </html>
#    EOF
#
#        return $content;
#    }

}

